import {findBanners, findCategory, findListGoods, findRecommendGoods, getCategory1} from '../../utils/api'
// index.js
Page({
  data:{
    bannerList:[],//存放轮播数据
    CategoryList:[],//一级分类列表数据
    FindListGoods:[],//猜你喜欢
    RecommendGoods:[],//推荐更多
  },
  onLoad() {
    this.getBanners();
    this.getCategory();
    this.getfindListGoods();
    this.getRecommend();
  },
  //获取轮播图数据
  async getBanners(){
    try {
      let result = await findBanners();
      // console.log(result)
      if(result.code === 200){
        this.setData({
          bannerList:result.data,
        })
      }
    } catch (error) {
      console.log(error);
    }
  },
  //获取一级分类数据
  async getCategory(){
    try {
      let result = await getCategory1();
      if(result.code === 200){
        this.setData({
          CategoryList:result.data,
        })
      }
    } catch (error) {
      console.log(error);
    }
  },
  //猜你喜欢
  async getfindListGoods(){
    try {
      let result = await findListGoods();
      if(result.code === 200){
        this.setData({
          FindListGoods:result.data,
        })
      }
    } catch (error) {
      console.log(error);
    }
  },
  //推荐更多
  async getRecommend(){
    try {
      let result = await findRecommendGoods();
      if(result.code === 200){
        this.setData({
          RecommendGoods:result.data,
        })
      }
    } catch (error) {
      console.log(error)
    }
  },
  
})
